﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
using System.Data;

namespace ReadWriteFiles
{
    public class FilesManager
    {

        public static void fileWriter(List<string> lines, string path)
        {
            try
            {
                StreamWriter sw = new StreamWriter(path);
                for (int i = 0; i < lines.Count; i++)
                {
                    sw.WriteLine(lines[i].Trim());
                }
                sw.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
            finally
            {
                Console.WriteLine("Executing finally block.");
            }
        }        

        public static List<string> fileReader(string path)
        {
            List<string> text = new List<string>();
            String line = "";
            try
            {
                StreamReader sr = new StreamReader(path);
                while (line != null)
                {
                    line = sr.ReadLine();
                    if (line != null)
                    {
                        text.Add(line);
                    }
                }
                sr.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
            finally
            {
                Console.WriteLine("Executing finally block.");
            }
            return text;
        }
    }
}
